package com.wgts.wgts.control.dialog;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/*
 *
 *
 *   data:2018/10/1215:19
 *
 */public class RuleDialogFragment extends AbstractCustomDialogFragment {
    private static final String awardDialogBundle = "awardDialogBundle";
    public static String dialogType = "type" ;
    public static final String AWARD = "AWARD";
    public static final String GUESSING = "GUESSING";
    @BindView(R.id.award_show_text)
    TextView awardShowText;
    @BindView(R.id.close_dialog)
    ImageView closeDialog;
    @BindView(R.id.dialog_bg_ly)
    LinearLayout dialogBgLy;
    Unbinder unbinder;
    private String showText, type;

    @Override
    public void onStart() {
        super.onStart();
        // 设置宽度为屏宽, 靠近屏幕底部。
        Window win = getDialog().getWindow();
        // 一定要设置Background，如果不设置，window属性设置无效
        win.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);

        WindowManager.LayoutParams params = win.getAttributes();
        params.gravity = Gravity.CENTER;
        // 使用ViewGroup.LayoutParams，以便Dialog 宽度充满整个屏幕
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        win.setAttributes(params);
    }

    @Override
    public View onCreateDialogView() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            showText = bundle.getString(awardDialogBundle);
            type = bundle.getString(dialogType);
        }
        View view = LayoutInflater.from(getContext()).inflate(R.layout.rule_dialog_fragment, null);
        unbinder = ButterKnife.bind(this, view);

        return view;
    }

    public static RuleDialogFragment getAwardDialogFragment(String ruleText, String Type) {
        RuleDialogFragment fragment = new RuleDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putString(dialogType, Type);
        bundle.putString(awardDialogBundle, ruleText);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.close_dialog)
    public void onViewClicked() {
        dismiss();
    }
}
